﻿// KittyFeral PVE - HB Routine for FeralDruid 5.4 - By Neyia
using Styx;
using Styx.Common;
using Styx.CommonBot;
using Styx.CommonBot.Routines;
using Styx.Pathing;
using Styx.TreeSharp;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using Action = Styx.TreeSharp.Action;

namespace KittyFeral
{
    public partial class Main : CombatRoutine
    {
        Composite GuardianRotation()
        {
            return 
                new PrioritySelector(
                Cast(BEAR_FORM, ret => Me.Shapeshift != ShapeshiftForm.Bear),
                HealthstoneBear(),
                FaceMyTarget(),
                Cast(HEALING_TOUCH, ret => gotTarget && IsOverlayed(HEALING_TOUCH_INT)),
                Cast(FAERIE_FIRE, ret => gotTarget
                    && SpellManager.HasSpell(FAERIE_FIRE)
                    && !SpellManager.HasSpell(FAERIE_SWARM)
                    && !spellOnCooldown(FAERIE_FIRE)
                    && (!debuffExists(WEAKENED_ARMOR, Me.CurrentTarget) || !debuffExists(FAERIE_FIRE, Me.CurrentTarget))),
                Cast(FAERIE_SWARM, ret => gotTarget
                    && !SpellManager.HasSpell(FAERIE_SWARM)
                    && !spellOnCooldown(FAERIE_FIRE)
                    && (!debuffExists(WEAKENED_ARMOR, Me.CurrentTarget) || !debuffExists(FAERIE_SWARM, Me.CurrentTarget))),
                Cast(GROWL, ret => 
                    gotTarget 
                    && Me.CurrentTarget.ThreatInfo.RawPercent < 75 
                    && NotHaveRaidbot() 
                    && !spellOnCooldown(GROWL)
                    && Me.CurrentTarget.Distance <= 35),
                Cast(BONE_SHIELD, ret => SpellManager.HasSpell(BONE_SHIELD) && !buffExists(BONE_SHIELD, Me) && !spellOnCooldown(BONE_SHIELD)),
                Cast(CONSECRATION, ret => gotTarget && SpellManager.HasSpell(CONSECRATION) && !spellOnCooldown(CONSECRATION)),
                Cast(ELUSIVE_BREW, ret => gotTarget && SpellManager.HasSpell(ELUSIVE_BREW) && !spellOnCooldown(ELUSIVE_BREW) && Me.HealthPercent <= CRSettingsBear.myPrefs.useElusiveBrew),
                Cast(WILD_CHARGE, ret => gotTarget 
                    && SpellManager.HasSpell(WILD_CHARGE) 
                    && CRSettingsBear.myPrefs.useWildCharge
                    && !spellOnCooldown(WILD_CHARGE) 
                    && CanCastWildCharge(8, 25)),
                
                Cast(CENARION_WARD, ret => SpellManager.HasSpell(CENARION_WARD) && !spellOnCooldown(CENARION_WARD) && Me.HealthPercent <= CRSettingsBear.myPrefs.CenarionWard),
                Cast(ENRAGE, ret => Me.RagePercent <= 30 
                    && !spellOnCooldown(ENRAGE)),
                new Decorator(ret => gotTarget && Me.Combat && CRSettingsBear.myPrefs.useVirmenPotions && isBoss && !Me.CurrentTarget.Name.Contains("Dummy") && Me.CurrentTarget.IsWithinMeleeRange, new Action(ret => { VirmenPotion(); return RunStatus.Failure; })),
                
                new Decorator(ret => gotTarget && Me.Combat && isBoss && Me.CurrentTarget.IsWithinMeleeRange, new Action(ret => { UseEngiGloves(); return RunStatus.Failure; })),
                new Decorator(ret => gotTarget && buffExists(BERSERK, Me) && Me.CurrentTarget.IsWithinMeleeRange, MangleBerserk()),
                Cast(FORCE_OF_NATURE, ret => gotTarget && CRSettingsBear.myPrefs.ForceOfNature && !isBoss && UseForceOfNaure),
                Cast(FORCE_OF_NATURE, ret => gotTarget && CRSettingsBear.myPrefs.ForceOfNature && isBoss && !spellOnCooldown(FORCE_OF_NATURE)),
                Cast(BARKSKIN, ret => gotTarget && Me.HealthPercent <= CRSettingsBear.myPrefs.Barkskin && !spellOnCooldown(BARKSKIN) && LastSpell != BARKSKIN),
                Cast(MIGHT_OF_URSOC, ret => gotTarget && Me.HealthPercent <= CRSettingsBear.myPrefs.MightOfUrsoc && !spellOnCooldown(MIGHT_OF_URSOC)),
                Cast(FRENZIED_REGENERATION, ret => gotTarget && Me.HealthPercent <= CRSettingsBear.myPrefs.FrenziedRegeneration && !spellOnCooldown(FRENZIED_REGENERATION) && LastSpell != FRENZIED_REGENERATION),
                Cast(SURVIVAL_INSTINCTS, ret => gotTarget && Me.HealthPercent <= CRSettingsBear.myPrefs.SurvivalInstincts && !spellOnCooldown(SURVIVAL_INSTINCTS) && LastSpell != SURVIVAL_INSTINCTS),
                Cast(MAUL, ret => gotTarget && ((buffExists(TOOTH_AND_CLAW, Me) && Me.RagePercent >= 30) || Me.RagePercent >= 70) && !spellOnCooldown(MAUL)),
                Cast(MAUL, ret => gotTarget && Me.RagePercent >= 30 && !SpellManager.HasSpell(LACERATE) && !spellOnCooldown(MAUL)),
                Cast(MIGHTY_BASH, ret => gotTarget 
                    && !spellOnCooldown(MIGHTY_BASH) 
                    && Me.CurrentTarget.IsCasting
                    && (Me.CanInterruptCurrentSpellCast || NeedInterrupt)
                    && CRSettingsBear.myPrefs.AutoInterrupt 
                    && LastSpell != MIGHTY_BASH 
                    && LastSpell != SKULL_BASH ),
                Cast(SKULL_BASH, ret => gotTarget 
                    && !spellOnCooldown(SKULL_BASH) 
                    && Me.CurrentTarget.IsCasting
                    && (Me.CanInterruptCurrentSpellCast || NeedInterrupt)
                    && CRSettingsBear.myPrefs.AutoInterrupt 
                    && LastSpell != MIGHTY_BASH 
                    && LastSpell != SKULL_BASH ),
                Cast(WAR_STOMP, ret => gotTarget 
                    && Me.Race == WoWRace.Tauren 
                    && !spellOnCooldown(WAR_STOMP) 
                    && Me.CurrentTarget.IsCasting
                    && (Me.CanInterruptCurrentSpellCast || NeedInterrupt)
                    && CRSettingsBear.myPrefs.AutoInterrupt 
                    && LastSpell != MIGHTY_BASH 
                    && LastSpell != SKULL_BASH ),
                Cast(BERSERK, ret => gotTarget && isBoss && !spellOnCooldown(BERSERK)),
                Cast(BERSERKING, ret => gotTarget && isBoss && CRSettingsBear.myPrefs.useBerserking && NotHaveHasteBuffs() && !spellOnCooldown(BERSERKING) && LastSpell != BERSERKING && Me.CurrentTarget.IsWithinMeleeRange),
                Cast(INCARNATION, ret => gotTarget && isBoss && CRSettingsBear.myPrefs.useIncarnation && !spellOnCooldown(INCARNATION) && LastSpell != INCARNATION && Me.CurrentTarget.IsWithinMeleeRange),
                Cast(SAVAGE_DEFENSE, ret => gotTarget && Me.RagePercent >= 60 && !buffExists(SAVAGE_DEFENSE, Me) && Me.HealthPercent <= CRSettingsBear.myPrefs.SavageDefense),

                Trinket1Bear(),
                Trinket2Bear(),

                Cast(LIFEBLOOD, ret => gotTarget && SpellManager.HasSpell(LIFEBLOOD)
                     && isBoss
                     && CRSettingsBear.myPrefs.useLifeblood
                     && NotHaveHasteBuffs()
                     && !spellOnCooldown(LIFEBLOOD)
                     && Me.CurrentTarget.IsWithinMeleeRange),
                 Cast(THRASH, ret => gotTarget && !spellOnCooldown(THRASH) && !debuffExists(THRASH, Me.CurrentTarget)),
                 Cast(FAERIE_FIRE, ret => gotTarget && !spellOnCooldown(FAERIE_FIRE) && !debuffExists(WEAKENED_ARMOR, Me.CurrentTarget)),
                 Cast(MANGLE, ret => gotTarget && !spellOnCooldown(MANGLE)),
                 Cast(SWIPE, ret => gotTarget && !PauseAoe && addCount > 1 && !spellOnCooldown(SWIPE)),
                 Cast(LACERATE, ret => gotTarget && !spellOnCooldown(LACERATE))
                );
        }
        Composite MangleBerserk()
        {
            return new PrioritySelector(
                Cast(MANGLE, ret => gotTarget)
                );
        }
        Composite WildCharging()
        {
            return new Decorator(ret => gotTarget && SpellManager.HasSpell(WILD_CHARGE) 
                && !spellOnCooldown(WILD_CHARGE) 
                && SpellManager.CanCast(WILD_CHARGE)
                && (Me.CurrentTarget.Distance >= 8 && Me.CurrentTarget.Distance <= 25)
                && Me.CurrentTarget.InLineOfSight,
                new Action(ret =>
                {
                    SpellManager.Cast(WILD_CHARGE, Me.CurrentTarget);
                    Logging.Write(Colors.HotPink, WILD_CHARGE);
                    LastSpell = WILD_CHARGE;
                    return RunStatus.Failure;
                }));
        }
    }
}
